package com.mc2014.follow_me_2014;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockActivity;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class HomeActivity extends SherlockActivity 
{

	
	private ActionBar actionbar;
	private View custom_actionbar_layout;
	private String nickName;
	private LayoutInflater inflater;
	private TextView actionbar_title;
	private LinearLayout actionbar_menu;
	private Button menu1,menu2,menu3;
	private View view_for_click;
	private Intent i ;
	private ImageView triangle_img;
	private boolean isVisible = false;
	
	
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.activity_home);
	    
	    actionbar = getSupportActionBar();
	    actionbar.setDisplayShowTitleEnabled(false);
		actionbar.setDisplayShowHomeEnabled(false);
	    
	    inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		custom_actionbar_layout = inflater.inflate(R.layout.actionbar_layout,null);
		actionbar_title = (TextView)custom_actionbar_layout.findViewById(R.id.actionbar_title);
		actionbar_menu = (LinearLayout)findViewById(R.id.actionbar_menu);
		view_for_click = (View)findViewById(R.id.view_for_click);
		
		menu1 = (Button)findViewById(R.id.topic);
		menu2 = (Button)findViewById(R.id.fun_list);
		menu3= (Button)findViewById(R.id.photo_list);
		
		triangle_img = (ImageView)custom_actionbar_layout.findViewById(R.id.triangle);
		
		
		nickName = "춤추며 밥먹는 사자 ";
		
		//액션바 메뉴 설정
		actionbar_title.setText(nickName);
		actionbar_title.setOnClickListener(actionbarClick);
		view_for_click.setOnClickListener(viewClick);
		
		menu1.setOnClickListener(menuClick);
		menu2.setOnClickListener(menuClick);
		menu3.setOnClickListener(menuClick);
		
		
		actionbar.setCustomView(custom_actionbar_layout,
				new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT,
						ActionBar.LayoutParams.MATCH_PARENT));
		actionbar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
	    
	    
	    
	    
	}
	
	private OnClickListener actionbarClick = new OnClickListener() 
	{
		
		@Override
		public void onClick(View v) 
		{	
			if(isVisible == false)
			{
				actionbar_menu.setVisibility(View.VISIBLE);
				view_for_click.setVisibility(View.VISIBLE);
				triangle_img.setImageResource(R.drawable.triangle_ch);
				isVisible = true;
			}
			else
			{
				actionbar_menu.setVisibility(View.GONE);
				view_for_click.setVisibility(View.GONE);
				triangle_img.setImageResource(R.drawable.triangle);
				isVisible = false;
			}

		}
	};
	
	private OnClickListener viewClick = new OnClickListener() 
	{
		
		@Override
		public void onClick(View v) 
		{
			actionbar_menu.setVisibility(View.GONE);
			view_for_click.setVisibility(View.GONE);
			triangle_img.setImageResource(R.drawable.triangle);
			
		}
	};


	private OnClickListener menuClick = new OnClickListener() 
	{
		
		@Override
		public void onClick(View v) 
		{
			
			switch(v.getId())
			{
			case R.id.topic:
				
				Intent i = new Intent(HomeActivity.this,SubmitActivity.class);
				startActivity(i);
				break;
			case R.id.fun_list:
				i = new Intent(HomeActivity.this,ListLikedActivity.class);
				startActivity(i);
				break;
			case R.id.photo_list:
				
				i = new Intent(HomeActivity.this,ListUploadedActivity.class);
				startActivity(i);
				
				break;
			}
			
		}
	};

}
